#include <stdio.h>
#include <string.h>

int romanToInt(char *s)
{
    int sum = 0;
    int len = strlen(s);
    int a[10] = {0};
    int i = 0; 
    for(; i < len; i++)
    {
        switch(s[i])
        {
        case 'I':a[i] = 1;
                 break;
        case 'V':a[i] = 5;
                 break;
        case 'X':a[i] = 10;
                 break;
        case 'L':a[i] = 50;
                 break;
        case 'C':a[i] = 100;
                 break;
        case 'D':a[i] = 500;
                 break;
        case 'M':a[i] = 1000;
                 break;
        default: a[i] = 0;
        }
    }
    for(i = 0; i < len-1; i++)
    {
        if( a[i] >=  a[i+1])
        {
            sum = sum + a[i];
        }
        else
        {
            sum = sum - a[i] +a[i+1];
            i++;
        }
    }
    if(len==1)return a[0];           
    if(a[len-1] <= a[len-2])
    sum = sum + a[len-1];                    
    return sum; 
}
int main()
{
    char *s = "LVII";
    printf("%d\n",romanToInt(s));
}